"""
封装页面表现层:制作页面元素定位器
Page类继承Base类
"""
Login_url = "http://localhost:8080/ecshop/user.php"
from Common.Base import Base, open_browser


class LoginPage(Base):
    """封装页面表现层"""
    username_loc = ("name", "username")  # 用户名输入框
    password_loc = ("name", "password")  # 密码输入框
    remember_loc = ("id", "remember")  # 记住密码选择框
    submit_loc = ("class name", "us_Submit")  # 立即登录按钮
    question_loc = ("link text", "密码问题")  # 找回密码-密码问题
    email_loc = ("link text", "邮件")  # 找回密码-邮件
    message_loc = ("link text", "message")  # 找回密码-短信验证
    register_loc = ("css selector", "div[class=usTxt] a img")  # 立即注册按钮
    homepage_loc = ("link text", "首页")  # 首页按钮
    result_loc = ("class name", "f4_b")  # 登录结果

    """封装页面操作层:对页面元素进行操作"""

    def input_username(self, username):
        """
        用户名输入
        :param username: username
        :return:
        """
        self.send_keys(text=username, locator=self.username_loc)

    def input_password(self, password):
        """
        密码输入
        :param password:password
        :return:
        """
        self.send_keys(text=password, locator=self.password_loc)

    def login_remember_password(self):
        """
        记住密码
        :return:
        """
        self.click(locator=self.remember_loc)

    def login_submit(self):
        """
        立即登录
        :return:
        """
        self.click(locator=self.submit_loc)

    def login_find_question(self):
        """
        找回密码-密码问题
        :return:
        """
        self.click(locator=self.remember_loc)

    def login_find_question_email(self):
        """
        找回密码-邮件
        :return:
        """
        self.click(locator=self.email_loc)

    def login_find_question_message(self):
        """
        找回密码-短信验证
        :return:
        """
        self.click(locator=self.message_loc)

    def login_register(self):
        """
        立即注册
        :return:
        """
        self.click(locator=self.register_loc)

    def login_homepage(self):
        """
        首页链接
        :return:
        """
        self.click(locator=self.homepage_loc)

    def is_login_success(self, username):
        """
        判断登录是否成功
        :return:
        """
        return self.is_text_in_element(text=username, locator=self.result_loc)


    def member_login(self, username, password):
        """测试账号登录"""
        self.input_username(username=username)
        self.input_password(password=password)
        self.login_submit()


if __name__ == '__main__':
    import time

    driver = open_browser()
    page = LoginPage(driver)
    page.open_url(Login_url)
    page.input_username("小乔")
    # page.login_password("123456")
    # page.login_remember_password()
    # page.login_submit()
    page.login_register()
    time.sleep(3)
    page.close_browser()
